<?php

function city($str){
	$arr = explode('/',$str);
	if($arr&&count($arr)>2){

		return "居住城市:".$arr[0].$arr[1];
	}else{
		return "居住城市：未知";
	}
}

function get_age($str){
	if($str){
		$birthday = strtotime($str);
		$byear = date('Y',$birthday);
	 	$bmonth = date('m',$birthday);
		$bday = date('d',$birthday);
	 	$tyear = date('Y');
	    $tmonth = date('m');
	    $tday = date('d');
	    $age = $tyear - $byear;
	    if($bmonth>$tmonth ||$bmonth==$tmonth && $bday>$tday){
	    	$age--;
	    }
	    return $age."岁";
	}else{
		return "未知岁数";
	}
}
  

function height($str){
	if($str){
		return "身高：".$str."cm";
	}else{
		return "身高：未知";
	}
}

function weight($str){
	if($str){
		return "体重：".$str."kg";
	}else{
		return "体重：未知";
	}
}

function education($education_id){
	$name = db('education')->where(['id'=>$education_id])->value('name');
	if($name){
		return "学历：".$name;
	}else{
		return "学历：未知";
	}
}

function get_age1($age_id){
	$name = db('age')->where(['id'=>$age_id])->value('name');
	if($name){
		return "年龄：".$name;
	}else{
		return "年龄：不限";
	}
}

function get_height1($height_id){
	$name = db('height')->where(['id'=>$height_id])->value('name');
	if($name){
		return "身高：".$name;
	}else{
		return "身高：不限";
	}
}
function income($income_id){
	$name = db('income')->where(['id'=>$income_id])->value('name');
	if($name){
		return "收入：".$name;
	}else{
		return "收入：未知";
	}
}


function zodiac($zodiac_id){
	$name = db('zodiac')->where(['id'=>$zodiac_id])->value('name');
	if($name){
		return "星座：".$name;
	}else{
		return "星座：未知";
	}
}


function marriage($marriage_id){
	$name = db('marriage')->where(['id'=>$marriage_id])->value('name');
	if($name){
		return "婚姻状况：".$name;
	}else{
		return "婚姻状况：未知";
	}
}

function car($car_id){
	$name = db('car')->where(['id'=>$car_id])->value('name');
	if($name){
		return "车辆状况：".$name;
	}else{
		return "车辆状况：未知";
	}
}

function house($house_id){
	$name = db('house')->where(['id'=>$house_id])->value('name');
	if($name){
		return "房产状况：".$name;
	}else{
		return "房产状况：未知";
	}
}

function get_tags($tags_ids){
	$data = db('tags')->where(['id'=>['in',$tags_ids]])->select();
	$tags = [];
	if($data){
		foreach ($data as $key => $value) {
			$tags[] = $value['name'];
		}
	}
	return $tags;
}

function gender($gender){
	if($gender==0){
		return '男';
	}else{
		return '女';
	}
}

// 应用公共文件

function geturl($url){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $output = curl_exec($ch);
    curl_close($ch);
    $jsoninfo = json_decode($output, true);
    return $jsoninfo;
}


function posturl($url,$data){
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    $out = curl_exec($ch);
    curl_close($ch);
    $jsoninfo = json_decode($out, true);
    return $jsoninfo;
}


function subtext($text,$length)
{
	if(mb_strlen($text, 'utf8')>$length){
		return mb_substr($text, 0, $length, 'utf8');
	}else{
		return $text;
	}
}
 

